<template>
  <div class="login-container">
    <el-form class="login-form" autoComplete="on" :model="loginForm" :rules="loginRules" ref="loginForm" label-position="left">
      <h3 class="title">外卖商户管理系统</h3>
    <div class="login-mask">
        <!--<div class="tab-border">-->
          <!--<el-row>-->
            <!--<template v-if="urlType === -1">-->
              <!--<el-col v-for="tab,index in tabArr" :key="tab" :span="8">-->
                <!--<div class="tab-name" :class="{'active':index===currTab}" @click="currTab=index">{{tab}}</div>-->
              <!--</el-col>-->
            <!--</template>-->
            <!--<template v-else>-->
              <!--<div class="tab-name active">{{tabArr[urlType]}}</div>-->
            <!--</template>-->
          <!--</el-row>-->
        <!--</div>-->
        <el-form-item prop="username">
        <span class="svg-container svg-container_login">
          <svg-icon icon-class="user" />
        </span>
          <el-input name="username" type="text" v-model="loginForm.username" autoComplete="on" placeholder="用户名" />
        </el-form-item>
        <el-form-item prop="password">
        <span class="svg-container">
          <svg-icon icon-class="password"></svg-icon>
        </span>
          <el-input name="password" :type="pwdType" @keyup.enter.native="handleLogin" v-model="loginForm.password" autoComplete="on"
                    placeholder="密码"></el-input>
          <span class="show-pwd" @click="showPwd"><svg-icon icon-class="eye" /></span>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="width:100%; font-size: 18px;" :loading="loading" @click.native.prevent="handleLogin">
            登 录
          </el-button>
        </el-form-item>
        <div class="copyright">Copyright  2017 技术支持：<a href="http://idaoying.com/">厦门云迁信息科技有限公司</a></div>
    </div>
    </el-form>
  </div>
</template>

<script>

export default {
  name: 'login',
  data() {
    return {
      urlType: 0,
      tabName: '',
      tabArr: [
        '商户端',
        '设计师端',
        '管理端'
      ],
      currTab: 0,
      loginForm: {
        username: '15160104305',
        password: '123456'
        // username: '',
        // password: ''
      },
      loginRules: {
        username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 18, message: '密码长度6-18位', trigger: 'blur' }
        ]
      },
      loading: false,
      pwdType: 'password'
    }
  },
  methods: {
    showPwd() {
      if (this.pwdType === 'password') {
        this.pwdType = ''
      } else {
        this.pwdType = 'password'
      }
    },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          this.$store.dispatch('Login', {
            username: this.loginForm.username,
            password: this.loginForm.password,
            role: this.currTab + 1
          }).then((res) => {
            console.log('login success', res)
            this.loading = false
            this.$router.push({ path: '/home' })
          }).catch(() => {
            console.log('login fail')
            this.loading = false
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    handleTabClick(tab) {
      console.log(tab)
    }
  },
  created() {
    console.log(window.location.href)
    const url = window.location.href
    // const url = 'http://admin.sjh.xmmost.com/#/login'
    if (url.indexOf('merchant.') >= 0) {
      this.urlType = 0
    } else if (url.indexOf('designer.') >= 0) {
      this.urlType = 1
    } else if (url.indexOf('admin.') >= 0) {
      this.urlType = 2
    } else {
      this.urlType = -1
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
$bg:#2d3a4b;
$light_gray:#eee;

/* reset element-ui css */
.login-container {
  .el-input {
    display: inline-block;
    height: 40px;
    width: 85%;
    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: #666666;
      height: 40px;
      &:-webkit-autofill {
        -webkit-box-shadow: 0 0 0px 1000px #fff inset !important;
        -webkit-text-fill-color: #666666 !important;
      }
    }
  }
  .el-form-item {
    height: 42px;
    /*line-height: 40px;*/
    border: 1px solid #d3d4d5;
    background: #fff;
    border-radius: 5px;
    color: #454545;
    .el-form-item__content {
      height: 40px;
    }
  }
}

</style>

<style rel="stylesheet/scss" lang="scss" scoped>
$bg:#2d3a4b;
$dark_gray:#889aa4;
$light_gray:#eee;
.login-container {
  background: url(https://gw.alipayobjects.com/zos/rmsportal/TVYTbAXWheQpRcWDaDMu.svg) no-repeat center 110px;
  background-color: #F0F2F5;
  background-size: 100%;
  position: fixed;
  height: 100%;
  width: 100%;
  .login-form {
    position: absolute;
    left: 0;
    right: 0;
    width: 560px;
    padding: 35px 35px 15px 35px;
    margin: 220px auto;
  }
  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;
    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }
  .svg-container {
    padding: 0px 5px 0px 15px;
    color: $dark_gray;
    vertical-align: top;
    width: 30px;
    display: inline-block;
    &_login {
      font-size: 20px;
    }
  }
  .title {
    font-size: 34px;
    color: #2b2b2b;
    margin: 0px auto 20px auto;
    text-align: center;
    font-weight: bold;
  }
  .show-pwd {
    position: absolute;
    right: 10px;
    top: 0;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
  .copyright {
    margin-top: 80px;
    text-align: center;
    font-size: 14px;
    a {
      color: #66b1ff;
    }
  }
  .login-mask {
    padding: 40px;
    /*background-color: rgba(255, 255, 255, 0.15);*/
    border-radius: 10px;
  }
  .tab-border {
    border-bottom: 2px solid white;
    margin-bottom: 20px;
    font-size: 18px;
    height: 45px;
    line-height: 43px;
    .tab-name {
      text-align: center;
      height: 100%;
      cursor: pointer;
      font-weight: 600;
      &.active {
        color: #66d4d1;
        border-bottom: 2px solid #66d4d1;
        padding-bottom: -4px;
      }
    }
  }
}
</style>
